<?php

namespace Controller\Auth;

class Group extends \Controller\Base {

    public function actionIndex() {
        if ($this->isPost()) {
            $this->saveRoles();
        }
        $this->setMenuPath('Account', 'AuthGroup');
        $roleList = \Entity\Auth::instance()->getRoleList();
        $this->assign('roleList', $roleList);
        $groupList = \Business\Account::instance()->getGroupList();
        $this->assign('groupList', $groupList);
        $this->display();
    }

    private function saveRoles() {
        $groupId = $this->postInt('groupId');
        $roles = $this->postParam('roles', []);
        if (!$groupId) {
            $this->addWarningMsg('请选择分组');
            return;
        }
        \Business\Account::instance()->updateGroupRoles($groupId, $roles);
        $this->assign('groupId', $groupId);
    }
}